
const HERO_IDS = {
  ZHI: "zhi",      // 至（游戏开发）
  SAGI: "sagi",    // sagi（游戏策划）
  HEI: "heimao",   // 黑毛黑框厨（畜牧工商管理）
  TANG: "tang"     // 躺啊堂（游戏原画）
};

const PLAYER_ATTRS = ["art", "tech", "charm", "mana"]; // 玩家四项属性 key 列表

// 各女主对应的“主要依赖玩家属性”（用于检定/加成等）
const HERO_PROFESSION_ATTR = {
  [HERO_IDS.ZHI]: ["tech"],
  [HERO_IDS.SAGI]: ["mana"],
  [HERO_IDS.HEI]: ["charm", "mana", "art"], // 复合偏好（优先 charm）
  [HERO_IDS.TANG]: ["art"]
};

/**
 * Heroine（女主）数据结构
 * affinity / jealousy
 * cash: 金钱（数值）
 * fame: 知名度（数值，可用于结算）
 * meta: 可放置外观、剧情标记、已解锁事件等
 */
class Heroine {
  constructor(id, opts = {}) {
    this.id = id;
    this.name = opts.name || id;
    this.affinity = opts.affinity ?? 50;
    this.jealousy = opts.jealousy ?? 10;
    this.cash = opts.cash ?? 0;
    this.fame = opts.fame ?? 0;
    this.projectProgress = opts.projectProgress ?? 0;
    this.avatar = opts.avatar ?? "";
    this.meta = opts.meta ?? {}; // 存放事件标记、已读CG等
  }

  changecash(delta) {
    this.cash = this.cash + delta;
  }

  changeFame(delta) {
    this.fame = this.fame + delta;
  }

  setAvatar(avatar) {
    this.avatar = avatar;
  }

  getData() {
    return {
      affinity: this.affinity,
      jealousy: this.jealousy,
      cash: this.cash,
      fame: this.fame,
      projectProgress: this.projectProgress
    }
  }
}

/**
 * Player（玩家）数据结构
 * attrs: art/tech/charm/mana（数值，0..∞）
 * resources: stamina, cash, clues, arknightsLevel
 */
class Player {
  constructor(name, avatar, opts = {}) {
    this.name = name;
    this.avatar = avatar ?? "";

    // 基础属性
    this.attrs = {
      art: opts.art ?? 10,
      tech: opts.tech ?? 0,
      charm: opts.charm ?? 0,
      mana: opts.mana ?? 5
    };

    // 资源
    this.resources = {
      stamina: opts.stamina ?? 10,
      cash: opts.cash ?? 0,
      //clues: opts.clues ?? 0,
      arkLv: opts.arkLv ?? 0,
      insurance: opts.insurance ?? 0,
    };

    // 游戏进度/状态元数据（学期、日期、phase 等）
    this.meta = {
      day: opts.day ?? 1,
      term: opts.term ?? 1,
      isHoliday: opts.isHoliday ?? false,
      phase: opts.phase ?? "morning" // morning/midday/afternoon/evening
    };
  }

  changeStamina(delta) {
    this.resources.stamina = this.resources.stamina + delta
  }

  getStamina() {
    return this.resources.stamina;
  }

  changeCash(delta) {
    this.resources.cash = this.resources.cash + delta;
  }

  getCash() {
    return this.resources.cash;
  }

  addArkLv() {
    this.resources.arkLv += 1;
  }

  getArkLv() {
    return this.resources.arkLv;
  }

  addInsurance() {
    this.resources.insurance += 1;
  }

  getInsurance() {
    return this.resources.insurance;
  }

  useInsurance() {
    this.changeCash(this.resources.insurance * 2000);
    this.resources.insurance = 0;
  }
}

export { Heroine, Player, 
          HERO_IDS, PLAYER_ATTRS, HERO_PROFESSION_ATTR, };
